﻿using Cofe.Core.Entry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Cofe.Core
{
    public static class IEntryListImplExtension
    {
        public static async Task<IEntryLink[]> AddLinksAsync(this ICustomEntryList cel, params ICofeSystemInfo[] entries)
        {
            entries = (from e in entries where e != null select e).ToArray();
            if (entries.Length == 0)                
                throw new ArgumentException("AddLinks: Nothing to added");
            return (await EntryFE.LinkAsync(entries, cel, null, CancellationToken.None))
                .Select(e => e.As<IEntryLink>()).ToArray();
        }

        public static IEntryLink[] AddLinks(this ICustomEntryList cel, params ICofeSystemInfo[] entries)
        {
            return Task.Run<IEntryLink[]>(async () => await cel.AddLinksAsync(entries)).Result;
        }

        public static IEntryLink CreateLinkFolder(this ICustomEntryList cel, string name)
        {
            return cel.CreateAsync<IEntryLink>("directory", name).Result;
        }

    }
}
